<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en"xmlns:th="http://www.thymeleaf.org">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>软件园商城</title>
		<!-- Bootstrap core CSS -->
		<link href="css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link href="css/dashboard.css" th:href="@{/css/dashboard.css}" rel="stylesheet">
		<style type="text/css">
			/* Chart.js */
			@-webkit-keyframes chartjs-render-animation {
				from {
					opacity: 0.99
				}
				to {
					opacity: 1
				}
			}
			
			@keyframes chartjs-render-animation {
				from {
					opacity: 0.99
				}
				to {
					opacity: 1
				}
			}
			
			.chartjs-render-monitor {
				-webkit-animation: chartjs-render-animation 0.001s;
				animation: chartjs-render-animation 0.001s;
			}
		</style>
	</head>

	<body>
	<!--顶部导航 -->
	<div th:replace="~{topleft::topnav}"></div>
		<div class="container-fluid">
			<div class="row">
				<!--左边菜单 -->
				<div th:replace="~{topleft::#sidebarMenu(lurl='leftuser')}"></div>

				<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
					<h2>
						<form class="form-inline" th:action="@{/searchUsers}" method="get">
							<!-- 模糊姓名 -->
							<input type="text" name="name" class="form-control mb-2 mr-2"
								   placeholder="姓名" th:value="${name}">

							<!-- 精确性别（下拉框） -->
							<select name="sex" class="form-control mb-2 mr-2" th:value="${sex}">
								<option value="">全部性别</option>
								<option value="男">男</option>
								<option value="女">女</option>
							</select>

							<!-- 模糊地址 -->
							<input type="text" name="address" class="form-control mb-2 mr-2"
								   placeholder="地址" th:value="${address}">

							<button type="submit" class="btn btn-primary mb-2">搜索</button>
							<a class="btn btn-secondary mb-2 ml-2" th:href="@{/getUserList}">重置</a>
						</form>
						<a class="btn btn-success btn-sm" href="#" th:href="@{/AddUserById}">添加用户</a>
						<button class="btn btn-danger btn-sm ml-2"
								onclick="confirmDeleteAll()">删除全部</button>
					</h2>
					<div class="table-responsive">
						<table class="table table-sm table-hover table-bordered">
							<thead>
							<tr>
								<th>编号</th>
								<th>姓名</th>
								<th>性别</th>
								<th>年龄</th>
								<th>生日</th>
								<th>电话</th>
								<th>地址</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody>
							<tr th:each="user:${userList}">
								<td th:text="${user.id}"></td>
								<td th:text="${user.name}"></td>
								<td th:text="${user.sex}"></td>
								<td th:text="${user.age}"></td>
								<td th:text="${#dates.format(user.birthday,'yyyy-MM-dd')}"></td>
								<td th:text="${user.phone}"></td>
								<td th:text="${user.address}"></td>
								<td class="center">
									<a class="btn btn-success btn-sm" href="#" th:href="@{'/getUserById/'+${user.id}}">查看</a>
									<a class="btn btn-info btn-sm" href="#" th:href="@{'/updateUserById/'+${user.id}}">修改</a>
									<a class="btn btn-danger btn-sm" href="#" th:href="@{'/deleteUserById/'+${user.id}}">删去</a>
								</td>
							</tr>
							</tbody>
							<p style="color: red" th:text="${msg==''?'':msg}"></p>
						</table>
					</div>
					<div class="pagination">
    					<span th:if="${pageInfo.hasPreviousPage}">
        				<a th:href="@{/searchUsers(pageNum=1,
        				      name=${name}, sex=${sex}, address=${address})}">首页</a>
        				<a th:href="@{/searchUsers(pageNum=${pageInfo.prePage},
        					  name=${name}, sex=${sex}, address=${address})}">上一页</a>
    				</span>
						<span th:each="navPage : ${pageInfo.navigatepageNums}">
        					<a th:if="${navPage != pageInfo.pageNum}"
							   th:href="@{/searchUsers(pageNum=${navPage},
							   name=${name}, sex=${sex}, address=${address})}"
							   th:text="${navPage}"></a>
        				<span th:unless="${navPage != pageInfo.pageNum}"
							  th:text="${navPage}"
							  style="color:red;margin:0 5px;"></span>
    					</span>

						<span th:if="${pageInfo.hasNextPage}">
        					<a th:href="@{/searchUsers(pageNum=${pageInfo.nextPage},
        						name=${name}, sex=${sex}, address=${address})}">下一页</a>
        					<a th:href="@{/searchUsers(pageNum=${pageInfo.pages},
        						name=${name}, sex=${sex}, address=${address})}">尾页</a>
   						 </span>

						<span style="margin-left:20px;">
        					共 [[${pageInfo.total}]] 条记录
    					</span>
					</div>
					<style>
						.pagination { margin-top: 20px; }
						.pagination a {
							padding: 5px 10px;
							border: 1px solid #ddd;
							margin: 0 2px;
							text-decoration: none;
						}
					</style>
				</main>
			</div>
		</div>

		<!-- Bootstrap core JavaScript
    ================================================== -->
		<!-- Placed at the end of the document so the pages load faster -->
	<script type="text/javascript" src="js/jquery-3.2.1.slim.min.js" th:src="@{/js/jquery-3.2.1.slim.min.js}"></script>
	<script type="text/javascript" src="js/popper.min.js" th:src="@{/js/popper.min.js}"></script>
	<script type="text/javascript" src="js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>

	<!-- Icons -->
	<script type="text/javascript" src="js/feather.min.js" th:src="@{/js/feather.min.js}"></script>
	<script>
		feather.replace()
	</script>

	<!-- Graphs -->
	<script type="text/javascript" src="js/Chart.min.js" th:src="@{/js/Chart.min.js}"></script>
		<script>
			var ctx = document.getElementById("myChart");
			var myChart = new Chart(ctx, {
				type: 'line',
				data: {
					labels: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
					datasets: [{
						data: [15339, 21345, 18483, 24003, 23489, 24092, 12034],
						lineTension: 0,
						backgroundColor: 'transparent',
						borderColor: '#007bff',
						borderWidth: 4,
						pointBackgroundColor: '#007bff'
					}]
				},
				options: {
					scales: {
						yAxes: [{
							ticks: {
								beginAtZero: false
							}
						}]
					},
					legend: {
						display: false,
					}
				}
			});
		</script>
	<!-- 添加JavaScript确认和提交逻辑 -->
	<script>
		function confirmDeleteAll() {
			if (confirm('确定要删除所有符合条件的用户吗？此操作不可恢复！')) {
				// 获取当前搜索的用户名
				const keyword = document.querySelector('input[name="keyword"]').value;

				// 创建隐藏表单提交
				const form = document.createElement('form');
				form.method = 'POST';
				form.action = '/deleteAllByUsername';

				// 添加参数
				const input = document.createElement('input');
				input.type = 'hidden';
				input.name = 'name';
				input.value = keyword;
				form.appendChild(input);

				document.body.appendChild(form);
				form.submit();
			}
		}
	</script>

	</body>

</html>